﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DMS.Business.Modules.Configuation;
using DMS.Business.Utility;
using System.Configuration;
using System.Web;

namespace DMS.Business.Utility
{
    /// <summary>
    /// 常用系统参数
    /// </summary>
    public static class AppParams
    {
        public const string ConfigID_DeptFundsQuota = "DeptFundsQuota";
        public const string ConfigID_DeptMaterialQuota = "DeptMaterialQuota";
        public const string ConfigID_IsDeptCountUnit = "IsDeptCountUnit";
        public const string ConfigID_IsHault = "IsHault";
        public const string ConfigID_DeptRole = "DeptRole";

        public const string ConfigID_ApplicationTitle = "ApplicationTitle";
        public const string ConfigID_RootDeptCondition = "RootDeptCondition";
        public const string ConfigID_DeptManagerCondition = "DeptManagerCondition";
        public const string ConfigID_FileServer = "FileServer";
        public const string ConfigID_FileServerAccount = "FileServerAccount";
        public const string ConfigID_FileServerPassword = "FileServerPassword";

        public const string ConfigID_IsReceiveSMSAlert = "IsReceiveSMSAlert";
        public const string ConfigID_IsReceiveMailAlert = "IsReceiveMailAlert";
        public const string ConfigID_AlertBeginTimeSetting = "AlertBeginTimeSetting";
        public const string ConfigID_AlertEndTimeSetting = "AlertEndTimeSetting";
        public const string ConfigID_IsNeedValidCode = "IsNeedValidCode";
        public const string ConfigID_DeleBeginTime = "DelegateBeginTime";
        public const string ConfigID_DeleEndTime = "DelegateEndTime";

        /// <summary>
        /// 项目负责部门，市场部
        /// </summary>
        public const string ConfigID_MarketingDept = "广州移动本部>市场部";
        /// <summary>
        /// 项目负责部门，行政服务中心
        /// </summary>
        public const string ConfigID_AdminServiceCenter = "行政服务中心";

        public const string ConfigID_HrSyncRate = "HrSyncRate";

        /// <summary>
        /// 本应用名称
        /// </summary>
        public static string ApplicationTitle
        {
            get
            {
                string res = "广州移动办公物资管理平台";
                SysConfig config = ConfigHelper.GetSysConfigByID(AppParams.ConfigID_ApplicationTitle);
                if (config != null)
                {
                    res = config.Value; 
                }
                return res;
            }
        }

        

        /// <summary>
        /// 根部门条件
        /// </summary>
        public static string RootDeptCondition
        {
            get
            {
                string res = "AND [DeptCode] = '34920440002'";
                SysConfig config = ConfigHelper.GetSysConfigByID(AppParams.ConfigID_RootDeptCondition);
                if (config != null)
                {
                    res = config.Value;
                }
                return res;
            }
        }

        public static string DeptManagerCondition
        {
            get
            {
                string res = "AND [UserPosition] LIKE '%室经理'";
                SysConfig config = ConfigHelper.GetSysConfigByID(AppParams.ConfigID_DeptManagerCondition);
                if (config != null)
                {
                    res = config.Value;
                }
                return res;
            }
        }

        public static string FileServer
        {
            get
            {
                string res = "~/Attachments";
                /* DB Version
                SysConfig config = ConfigHelper.GetSysConfigByID(AppParams.ConfigID_FileServer);
                if (config != null)
                {
                    res = config.Value;
                }
                 * */

                res = ConfigurationManager.AppSettings[AppParams.ConfigID_FileServer].ToString();

                return res;
            }
        }
        public static string FileServerAccount
        {
            get
            {
                string res = ConfigurationManager.AppSettings[AppParams.ConfigID_FileServerAccount].ToString();
                return res;
            }
        }

        public static string FileServerPassword
        {
            get
            {
                string res = ConfigurationManager.AppSettings[AppParams.ConfigID_FileServerPassword].ToString();
                return res;
            }
        }

        public static string AppRoot
        {
            get
            {
                return string.Empty;
            }
        }
        public static bool AllowSMSPWD
        {
            get
            {
                return false;
            }
        }

        public static string Host
        {
            get
            {
                //string url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host;
                //if( HttpContext.Current.Request.Url.Port != 80)
                //    url += ":" + HttpContext.Current.Request.Url.Port.ToString();
                string host = ConfigurationManager.AppSettings["host"];
                string url = String.IsNullOrEmpty(host) ? "http://dms.gz.gmcc.net" : host;
                return url;
            }
        }

        /// <summary>
        /// 是否开启登陆验证码
        /// </summary>
        public static int IsNeedValidCode
        {
            get
            {
                int res = 1;
                SysConfig config = ConfigHelper.GetSysConfigByID(AppParams.ConfigID_IsNeedValidCode);
                if (config != null)
                {
                    res = int.Parse(config.Value);
                }
                return res;
            }
        }
    }
}
